package com.yjq.pojo;

/**
 * @author 尹嘉琪
 * @create 2021-12-09 21:13
 */
public class Triangle extends Shape {

    private double width; // 三角形的底

    private double height; // 三角形的高

    private double hypotenuse; // 斜边长

    private String shape;

    public Triangle() {
    }

    public Triangle(double width, double height, double hypotenuse) {
        this.width = width;
        this.height = height;
        this.hypotenuse = hypotenuse;
    }

    public String getShape() {
        return shape;
    }

    public void setShape(String shape) {
        this.shape = shape;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public double getHypotenuse() {
        return hypotenuse;
    }

    public void setHypotenuse(double hypotenuse) {
        this.hypotenuse = hypotenuse;
    }

    /**
     * 计算面积
     * @return
     */
    @Override
    Double calAre() {
        // 根据公式 面积 = 1 / 4 * ((a+b+c) * (a+b-c) * (a+c-b) * (b+c-a))
        return Math.sqrt((width + height + hypotenuse) * (width + height - hypotenuse) * (width + hypotenuse - height) * (height + hypotenuse - width)) / 4;
    }

    /**
     * 计算周长
     * @return
     */
    @Override
    Double calPer() {
        return width + height + hypotenuse;
    }

    /**
     * 输出相关信息
     * @return
     */
    @Override
    public String printMessage() {
        return  "当前三角形为：" + isWhatTringle() + "，面积为：" + calAre() + ", 周长为：" + calPer();
    }

    /**
     * 判断是否为三角形
     * @return
     */
    public boolean isTriangle () {
        // 如果边长小于等于0
        if (width <= 0 || height <= 0 || hypotenuse <= 0) {
            return false;
        }
        // 是个三角形
        if ((width + height) > hypotenuse && (width + hypotenuse) > height && (height + hypotenuse) > width) {
            double max = Math.max(Math.max(width, height), hypotenuse);
            if (max == width) {
                width = hypotenuse;
                hypotenuse = max;
            } else if (max == height){
                height = hypotenuse;
                hypotenuse = max;
            }
            return true;
        } else {
            return false;
        }
    }

    /**
     * 判断是否是什么三角形
     * @return
     */
    public String isWhatTringle() {
        // a*a + b*b < c*c
        if(width*width+height*height<hypotenuse*hypotenuse) {
            if(width==height) {
                shape = "等腰三角形";
                return "等腰三角形";
            }else {
                shape = "钝角三角形";
                return "钝角三角形";
            }
        }else if(width*width+height*height==hypotenuse*hypotenuse) {
            if(width==height) {
                shape = "等腰直角三角形";
                return "等腰直角三角形";
            }else {
                for(int i = 0; i < height; i++){
                    for(int j = 0; j < 2 * i + 1; j++){
                        System.out.print("*");
                    }
                    System.out.println();
                }
                shape = "直角三角形";
                return "直角三角形";
            }
        }else {
            if(width==height) {
                if(height==hypotenuse) {
                    shape = "等边三角形";
                    return "等边三角形";
                }else {
                    shape = "等腰三角形";
                    return "等腰三角形";
                }
            }else {
                shape = "锐角三角形";
                return "锐角三角形";
            }
        }
    }
}
